﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BtoBSWT315.User
{
    public partial class UserControl : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                if (Session["user"] == null)
                {
                    HyperLink1.Visible = false;
                    Response.Redirect("../Default.aspx");
                }
                else
                {
                    user2.Text = Session["user"].ToString();

                    HyperLink1.Visible = false;
                    if (Session["user"].ToString().Equals("jisuanji110"))
                    {
                        HyperLink1.Visible = true;
                        HyperLink1.Target = "_blank";
                        HyperLink1.NavigateUrl = "../Admin/Admin_Login.aspx";

                    }

                }

                //else
                //{
                //    user2.Text = Session["user"].ToString();

                //    //验证当前Session中是否有节点
                //    if (Session["treeNode"] != null)
                //    {
                //        TreeNode parentNode = Session["treeNode"] as TreeNode;
                //        //遍历TreeView的Nodes集合
                //        foreach (TreeNode tn in this.TreeView1.Nodes)
                //        {
                //            //若循环节点的文本与当前节点的文本匹配,展开该节点；反之折叠
                //            if (tn.Text.Trim() == parentNode.Text.Trim())
                //            {
                //                tn.Expand();
                //            }
                //            else
                //            {
                //                tn.Collapse();
                //            }

                //        }
                //    }
                //}
            }
        }

        /// <summary>
        /// 展开事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void TreeView1_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
        {   //获取当前节点
            TreeNode currentNode = e.Node;
            //验证当前Session中是否有节点
            if (Session["treeNode"] != null)
            {
                TreeNode node = Session["treeNode"] as TreeNode;
                //遍历TreeView的Nodes集合
                foreach (TreeNode tn in this.TreeView1.Nodes)
                {
                    //若循环节点的文本与当前节点的文本不匹配，将其余节点折叠
                    if (tn.Text.Trim() != currentNode.Text.Trim())
                    {
                        tn.Collapse();
                    }
                }


            }
            //存储当前节点
            Session["treeNode"] = currentNode;
        }
        /// <summary>
        /// 折叠事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void TreeView1_TreeNodeCollapsed(object sender, TreeNodeEventArgs e)
        {
            //移除存储的节点
            Session.Remove("treeNode");
        }
    }
}